package org.tsp.android.MapExample;


import org.tsp.android.MapExample.R;
import org.utils.setting.Setting;
import org.utils.setting.SettingMarkers;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class ConfigurationViewActivity extends Activity {
	
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.configuration_view);
        
        //recuperation des edit Box a mettre a jour
        TextView textViewDistance = (TextView) findViewById(R.id.editTextDistance);
        TextView textViewMDP = (TextView) findViewById(R.id.editTextMotDePasse);
        TextView textViewNbMarkers = (TextView) findViewById(R.id.editTextNombreMarkers);

        //mise a jour des edit box
        textViewMDP.setText(Setting.getInstance().getPassword());
        textViewDistance.setText(Integer.toString(SettingMarkers.getInstance().getDistanceActivationMarkers()/1000000));
        textViewNbMarkers.setText(Integer.toString(SettingMarkers.getInstance().getNombreDeMarkers()));
        
	}
	public void OnButtonValiderClick(View v){
/*		TextView textView = (TextView) findViewById(R.id.txtResolver);
		String message = "";
		if(String.valueOf(textView.getText()).equals(Setting.getInstance().getPassword())){
			message = "Bravo ! ! !";
		}else{
			message = "Try again";		
		}
		textView.setText(message);		
	}	
	public void OnButtonRetourClick(View v){
*/		 
		//recuperation des configuration saisie
        TextView textViewDistance = (TextView) findViewById(R.id.editTextDistance);
        TextView textViewMDP = (TextView) findViewById(R.id.editTextMotDePasse);
        TextView textViewNbMarkers = (TextView) findViewById(R.id.editTextNombreMarkers);
        
        //verification de la configuration saisie et enregistrement
        if(!String.valueOf(textViewDistance.getText()).equals("")){
        	try{
        		int distance = Integer.parseInt(String.valueOf(textViewDistance.getText()));
        		if (distance > 0){
        			SettingMarkers.getInstance().setDistanceActivationMarkers(distance);
        		}
        	}catch(Exception e){}
        }
        if(!String.valueOf(textViewNbMarkers.getText()).equals("")){
        	try{
        		int nbMarkers = Integer.parseInt(String.valueOf(textViewNbMarkers.getText()));
        		if (nbMarkers > 0){
        			SettingMarkers.getInstance().setNombreDeMarkers(nbMarkers);
        		}
        	}catch(Exception e){}
        }
        if(!String.valueOf(textViewMDP.getText()).equals("")){
        	Setting.getInstance().setPassword(String.valueOf(textViewMDP.getText()));
        }
        //passage sur la page principal
		Intent intent = new Intent(ConfigurationViewActivity.this,MainViewActivity.class);
	     startActivity(intent);		 
	}	
}
